package com.menu.Controller;

import com.menu.Service.BackgroundService;
import com.menu.Utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Api(tags = "背景接口")
public class BackgroundController {
    @Resource
    BackgroundService backgroundService;


    @ApiOperation("管理员添加首页背景")
    @PostMapping("/Admin/addBackground")
    public ResponseResult addBackground(@RequestPart MultipartFile backgroundSrc){
        return backgroundService.addBackground(backgroundSrc);
    }


    @ApiOperation("管理员修改首页背景")
    @PutMapping("/Admin/updateBackGround")
    public ResponseResult updateBackGround(@RequestPart MultipartFile backgroundSrc,Integer backgroundId){
        return backgroundService.updateBackGround(backgroundId,backgroundSrc);
    }

    @ApiOperation("遍历首页默认背景")
    @GetMapping("/Visitor/findBackgroundByState")
    public ResponseResult findBackgroundByState(){
        return backgroundService.findBackgroundByState();
    }


    @ApiOperation("管理员后台遍历所有背景")
    @GetMapping("/Admin/findAll")
    public ResponseResult findAll(Integer pageNow,Integer pageSize){
        return backgroundService.findAll(pageNow, pageSize);
    }

    @ApiOperation("管理员后台单个删除背景")
    @DeleteMapping("/Admin/deleteBackground")
    public ResponseResult deleteBackground(Integer backgroundId){
        return backgroundService.deleteBackground(backgroundId);
    }

    @ApiOperation("管理员后台批量删除背景")
    @DeleteMapping("/Admin/batchDeleteBackground")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "backgroundId", value = "背景id", required = true, allowMultiple = true,dataTypeClass = List.class)
            }
    )
    public ResponseResult batchDeleteBackground(Integer []backgroundId){
        return backgroundService.batchDeleteBackground(backgroundId);
    }


    @ApiOperation("管理员后台设置首页默认背景")
    @PostMapping("/Admin/updateBackgroundToOne")
    public ResponseResult updateBackgroundToOne(Integer backgroundId){
        return backgroundService.updateBackgroundToOne(backgroundId);
    }
}
